<!--
 * @Author: chunlai
 * @Date: 2023-12-11 18:03:21
 * @LastEditTime: 2025-11-26 10:16:50
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @FilePath: \01.latest-short-insure\src\views\form\components\HealthyPop.vue
 * @Description: 健康告知弹出框
-->
<template>
  <van-popup
    v-model="show"
    overlay-class="lay1_shark"
    round
    position="bottom"
    get-container="#app"
  >
    <div class="common_pop_main">
      <div class="pop_head_line">
        请确认被保人<strong>{{ getInsureName }}</strong
        >的健康告知
        <div class="back_btn" @click="closePop">
          <img :src="`${imgUrlPath}/icons/close.png`" alt="" />
        </div>
      </div>
      <div class="pop_conts_box">
        <p class="warn_top_msg" v-if="topMsg">
          <img :src="`${imgUrlPath}/icons/best.png`" class="best_icon" />
          <b v-html="topMsg"></b>
        </p>
        <div class="html_conts" v-html="healthConts"></div>
        <div class="warn_foot_msg">
          <b v-html="ftbMsg" v-if="ftbMsg"></b>
          <p v-html="ftpMsg" v-if="ftpMsg"></p>
        </div>
      </div>
      <div class="pop_foot_btns">
        <div
          class="yesno_btn some_yes"
          :class="autoHealthy != '0' ? 'can_suto' : ''"
          @click="someYesEvent"
        >
          <span :class="autoHealthy != '0' ? 'is_auto' : ''">{{
            leftBtnText
          }}</span>
        </div>
        <div class="yesno_btn all_no" @click="allNoEvent">
          {{ rightBtnText }}
        </div>
      </div>
    </div>
  </van-popup>
</template>

<script>
import { mapGetters } from "vuex";
import { getHealthNoticeUrl } from "@/utils/functions";
import { rebackUrlPath } from "@/methods/format.js";
export default {
  name: "HealthyPop",
  components: {},
  data() {
    return {
      show: false,
      pIdx: 0,
      healthConts: "",
      leftBtnText: "部分为是",
      rightBtnText: "以上全否",
    };
  },
  computed: {
    ...mapGetters({
      topMsg: "notice/topMsg",
      ftbMsg: "notice/ftbMsg",
      ftpMsg: "notice/ftpMsg",
      assuredList: "insert/assuredList",
      autoHealthy: "notice/autoHealthy",
    }),
    getInsureObj() {
      let res = {};
      if (this.assuredList) {
        res = this.assuredList[this.pIdx];
      }
      return res;
    },
    getInsureName() {
      let res = "";
      if (this.assuredList) {
        res = this.assuredList[this.pIdx].name;
      }
      return res;
    },
  },
  watch: {},
  created() {},
  mounted() {},
  methods: {
    initModuleDatas(pIdx) {
      this.pIdx = pIdx;
      this.show = true;
      this.$store.dispatch("json/getHealthyJson").then((res) => {
        if (res.healthConts) {
          this.healthConts = res.healthConts;
        }
        if (res.leftBtnText) {
          this.leftBtnText = res.leftBtnText;
        }
        if (res.rightBtnText) {
          this.rightBtnText = res.rightBtnText;
        }
        this.$store.commit("updateLoad", false);
      });
    },
    someYesEvent() {
      this.$store.dispatch("notice/watchNoticeChange");
      if (this.autoHealthy == "1") {
        this.toSmartHealthy("1");
      } else if (this.autoHealthy == "iframe") {
        this.toIframePage();
      } else {
        this.$toast("告知部分为是，不可投保");
        this.$emit("setValue", "N");
      }
    },
    toIframePage() {
      this.$baseConfirm(
        `被保人【${this.getInsureName}】健康告知不通过，可智能核保`,
        () => {
          this.$emit("close", "N");
          this.$router.push(`/iframe?pIdx=${this.pIdx}`);
        },
        null,
        "智能核保",
        "再看看"
      );
    },
    allNoEvent() {
      this.$store.dispatch("notice/watchNoticeChange");
      if (this.autoHealthy == "1") {
        this.toSmartHealthy("0");
      } else {
        this.$emit("close", "Y");
      }
    },
    closePop() {
      this.$emit("close");
    },
    toSmartHealthy(yesNo = "0", stype = "local") {
      const querys = this.$route.query;
      let rePath = ``;
      if (stype == "share") {
        rePath = `&orderNum=${this.orderNum}#/shareres?resvalue=1`;
      }
      let params = {
        ...this.apiComParams,
        choice: `${yesNo}`, //0：全部否, 1：部分是
        idType: this.getInsureObj.idType || "",
        idNo: this.getInsureObj.idNum || "",
        uwMedicalId: querys.uwMedicalId || "",
        undwrtDecideType: querys.undwrtDecideType || "",
        successUrl: `${rebackUrlPath(rePath)}?uid=${this.getInsureObj.idNum}`,
        failUrl: `${rebackUrlPath(rePath)}?uid=${this.getInsureObj.idNum}`,
      };
      this.$store.commit("updateLoad", true);
      getHealthNoticeUrl(params)
        .then(({ data }) => {
          this.$store.commit("updateLoad", false);
          if (data.code === "1") {
            if (data.url) {
              window.location.href = data.url;
            }
            if (yesNo == "0") {
              this.$emit("close", "Y");
            }
          } else {
            this.$toast(data.msg);
          }
        })
        .catch((err) => {
          this.$store.commit("updateLoad", false);
        });
    },
  },
};
</script>
<style lang="less" scoped>
.pop_conts_box {
  width: 100%;
  padding: 0 12px 30px;
  overflow-y: scroll;
}
.yesno_btn {
  width: 45%;
  height: 40px;
  line-height: 40px;
  border-radius: 22px;
  font-size: 15px;
  text-align: center;
  &.some_yes {
    border: 1px solid #f54040;
    color: #f54040;
    background: #fff;
    &.can_suto {
      line-height: normal;
    }
    .is_auto {
      &:after {
        content: "（部分支持智能核保）";
        width: 100%;
        display: block;
        font-size: 10px;
      }
    }
  }
  &.all_no {
    border: 1px solid #f54040;
    color: #fff;
    background: #f54040;
  }
}
.warn_top_msg {
  padding: 12px 0;
  .best_icon {
    float: left;
    width: 46px;
    height: 17px;
    margin-right: 5px;
  }
}
.warn_foot_msg {
  margin-top: 30px;
  p {
    font-size: 12px;
    background-color: rgb(246, 247, 249);
    padding: 10px 5px 10px 15px;
    margin-top: 10px;
    border-radius: 8px;
  }
}
b {
  color: #f54040;
  line-height: 17px;
}
.html_conts {
  font-family: 宋体;
  /deep/a {
    color: #2196f3;
  }
}
</style>
